package com.spring.boot.service.string;

import org.springframework.context.annotation.Description;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Redis中String类型数据
 *
 * @author LiKun
 * @date 2021/9/10 8:32
 */
@Service
public class StringService {

    @Resource
    private RedisTemplate redisTemplate;

    @Description("如果存在指定的Key，则为其设置值")
    public boolean setIfPresent(String key, String value) {
        return redisTemplate.boundValueOps(key).setIfPresent(value);
    }

    @Description("如果不存在指定的Key，则为其设置值")
    public boolean setIfAbsent(String key, String value) {
        return redisTemplate.boundValueOps(key).setIfAbsent(value);
    }

}
